﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

namespace ProjectBase.Core
{
    /// <summary>
    ///     IWriteDao allows to change the templated entity 'T'.
    ///     1) Add new instance (and check that no other with the same business meaning already exists)
    ///     2) Update existing instance (and assure that there already exists sucha an instance)
    ///     3) Delete the instance from the storage (if there is any)
    /// </summary>
    /// <typeparam name = "T">templated entity which has its persisted representation</typeparam>
    /// <typeparam name = "TID">unique identifier. suggested types are decimal, int, short, long, Guid and string</typeparam>
    [ContractClass(typeof(Diagnostics.WriteDao<,>))]
    public interface IWriteDao<T, in TID> : IDao
        where T : class, IPersistentObjectWithTypedId<TID>
    {
        /// <summary>
        ///     Basic write operation for insertingt. Stores (only new) entity.
        /// </summary>
        /// <param name = "entity">new transient entity</param>
        /// <returns>stored entity with defined identifier ID - or still transient entity if any error arises</returns>
        T Add(T entity);

        /// <summary>
        ///     Basic write operation for changing. Changes properties in the storage.
        /// </summary>
        /// <param name = "entity">entity which should be updated</param>
        /// <returns>updated entity - or still transient entity if any error arises</returns>
        T Update(T entity);

        /// <summary>
        ///     Basic write operation for deleting. Definitely removes entity from storage
        /// </summary>
        /// <param name = "entity"></param>
        void Delete(T entity);
    }
}